﻿/// <reference path="jquery-1.7.1-vsdoc.js" />


$(document).ready(function () {
    var worker = new Worker("Scripts/calculate.js");
    var data1 = 0;
    var data2 = 0;
    worker.onmessage = function (event) {
        var data = event.data;
        data2 = new Date().getTime();
        document.getElementById("result").innerHTML = "计算结果：" + data;
        document.getElementById("time").innerHTML = "workers 耗时：" + (data2 - data1) + "ms";
    };
    $("#cal").click(function () {
        data1 = new Date().getTime();
        var num = document.getElementById("num").value;
        var val = parseInt(num, 10);
        worker.postMessage(val);
    });
});





//var worker = new Worker("Scripts/calculate.js");
//var data1 = 0;
//var data2 = 0;
//worker.onmessage = function (event) {
//    var data = event.data;
//    data2 = new Date().getTime();
//    document.getElementById("result").innerHTML = "计算结果：" + data;
//    document.getElementById("time").innerHTML = "workers 耗时：" + (data2 - data1) + "ms";
//};
//function calculate() {
//    data1 = new Date().getTime();
//    var num = document.getElementById("num").value;
//    var val = parseInt(num, 10);
//    worker.postMessage(val);
//}